﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
namespace DAO
{
    public class ORDERDAO
    {
        public static void AddOrder(ORDER or)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            db.ORDERs.InsertOnSubmit(or);
            db.SubmitChanges();
        }
        public ORDER[] layBang()
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            return db.usp_SelectOrderAll().ToArray();
        }
        public ORDER[] SelectOrderByID(int idmember)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            return db.usp_SelectOrderByID(idmember).ToArray();
        }

        public static int SoLuongDaDat(int idPro)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            var temp = db.usp_COUNTORDER(idPro);
            String val = (temp.ToArray<usp_COUNTORDERResult>())[0].ORDER.ToString();
            if (val.Equals(""))
                return 0;
            return int.Parse(val);
        }
    }
}
